package cn.lijiajia3515.cairo.auth.framework.security.oauth2.server.authorization.jackson2;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;

import java.io.IOException;

public class OAuth2AuthorizationDeserializer extends JsonDeserializer<OAuth2Authorization> {

	@Override
	public OAuth2Authorization deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
		ObjectMapper mapper = (ObjectMapper) parser.getCodec();
		JsonNode root = mapper.readTree(parser);

		String id = JsonNodeUtils.findStringValue(root, "id");
		String registeredClientId = JsonNodeUtils.findStringValue(root, "registeredClientId");
		String principalName = JsonNodeUtils.findStringValue(root, "principalName");
		//mapper.write
		return null;

	}
}
